package cn.stylefeng.guns.generator.modular.service;

import com.baomidou.mybatisplus.mapper.SqlRunner;
import org.springframework.beans.factory.annotation.Value;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 获取数据库所有的表
 *
 * @author fengshuonan
 * @date 2017-12-04-下午1:37
 */
public class TableService {

    @Value("${spring.datasource.db-name:guns}")
    private String dbName;
    @Value("${spring.datasource.platform:}")
    private String platform;

    /**
     * 获取当前数据库所有的表信息
     */
    public List<Map<String, Object>> getAllTables() {
        List<Map<String, Object>> retList = new ArrayList<>();

        if (Objects.equals("h2", platform)) {
        } else {
            String sql = "select TABLE_NAME as tableName,TABLE_COMMENT as tableComment from information_schema.`TABLES` where TABLE_SCHEMA = '" + dbName + "'";
            List<Map<String, Object>> list = SqlRunner.db().selectList(sql);
            retList.addAll(list);
        }

        return retList;
    }
}
